package com.res0w.SMMS.ui.UDResource;

import java.awt.Component;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Insets;
import javax.swing.border.Border;

public class ImageBorder implements Border {

    private Insets insets = new Insets(0, 0, 0, 0);
    private Image image = null;

    public ImageBorder() {
        super();
    }

    public void setImage(Image image) {
        this.image = image;
    }

    public boolean isBorderOpaque() {
        return true;
    }

    public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
        if (image != null) {
            //一般在这里我们把窗口大小和图片大小设置刚好吻合
            int x0 = x + (width - image.getWidth(null))/2;
            int y0 = y + (height - image.getHeight(null))/2;
            g.drawImage(image, x0, y0, null);
        }
    }

    public Insets getBorderInsets(Component c) {
        //边距
        return insets;
    }
}